
		<div class="ui-portlet">
			{{template wxes/_user_wxes}}
			<ol class="breadcrumb">
			  <li><a href="/users/index"><i class="fa fa-home"></i>&nbsp;&nbsp;135公众平台</a></li>
			  <li class="active">管理菜单项</li>
			  <li>公众号：{{$current_wxinfo['Wx']['name']}}</li>
			</ol> 
		</div>          
       <hr>
    <div class="text-right">
    	<a href="?group=2">微信菜单</a>
    	<a href="?group=1">微网站导航</a>
    </div>   

<style>
.bs-navbar-preview .nav > li > a  {padding:10px 10px;}
.bs-navbar-preview .navbar-nav {float:none;}
.navbar-fixed-bottom .navbar-nav > li > .dropdown-menu{
	min-width: 100%;
    width: 100%;
}
.bs-navbar-preview .nav > li {border-right:1px solid #ddd;}
.bs-navbar-preview .nav > li:last-child{border-right:0 none;}
.text-danger {
    color: #f00;
}
</style>       
   
   {{if $group == 1}}
   <div>
       <a class="btn btn-primary" href="{{$this->Html->url(array('action'=>'add'))}}?group=1">新增微网站导航</a>
   </div>
   {{else}}
   		<section style="border: 0px none; padding: 0px;margin-bottom:15px;">
		    <section class="135brush layout" style="white-space: normal;font-size: 14px; line-height: 25px; margin: 2px auto; padding: 10px 10px; border: 2px dashed #dedcde;max-width: 100%;">
		        <p style="margin: 0 0;">
		            授权135后，不会影响公众号菜单的使用。如果需要在135配置菜单，需要进行<a href="/user_settings/setting?type=dev">开发者设置</a>。
		        </p>
		    </section>
		    <section style="display: block; width: 0; height: 0; clear: both;"></section>
		</section>

	   
	   {{if $current_wxinfo['Wx']['verify_type'] == -1 }}
		   <p style="color:red;">公众号未认证，只能允许设置微信素材中的内容作为菜单打开网址与回复消息。</p>
		   <div>
		       <a class="btn btn-primary" href="{{$this->Html->url(array('action'=>'add'))}}?group=2&type=view_limited">新增跳转网址菜单</a>
		       <a class="btn btn-primary" href="{{$this->Html->url(array('action'=>'add'))}}?group=2&type=media_id">新增发送消息菜单</a>
		       <a class="btn btn-warning" onclick="if(!confirm('是否确认要修改微信公众号的的菜单，将会覆盖现有菜单内容')) return false" href="{{$this->Html->url(array('action'=>'setMenu'))}}">同步菜单到微信公众号</a>
		   </div>
	   	{{else}}
		   	<p style="color:red;">公众号已认证</p>
		   <div>
		       <a class="btn btn-primary" href="{{$this->Html->url(array('action'=>'add'))}}?group=2&type=view">新增跳转网址菜单</a>
		       <a class="btn btn-primary" href="{{$this->Html->url(array('action'=>'add'))}}?group=2&type=click">新增发送消息菜单</a>
		       <a class="btn btn-warning" onclick="if(!confirm('是否确认要修改微信公众号的的菜单，将会覆盖现有菜单内容')) return false" href="{{$this->Html->url(array('action'=>'setMenu'))}}">同步菜单到微信公众号</a>
		   </div>		   
	   	{{/if}}
   {{/if}}
   
   
          
    <table class="ui-portlet table table-striped table-hover">
    <?php
        $tableHeaders =  $this->Html->tableHeaders(array(
            '菜单名称',
            '菜单类型',
			'回复消息key/打开网址',
            '操作',
        ));

        echo '<thead>'.$tableHeaders.'</thead>';

        $rows = array();
        foreach ($datalist AS $item) {
            $actions = $this->Html->link('修改', array('controller'=>'wx_menus','action' => 'edit', $item['WxMenu']['id']));
            $actions .= ' &nbsp; ' . $this->Html->link('排序前移', array('controller'=>'wx_menus','action' => 'moveUp', $item['WxMenu']['id']));
$actions .= ' &nbsp; ' .$this->Html->link('删除', array('controller'=>'wx_menus','action' => 'delete', $item['WxMenu']['id']),array('onclick'=>"if(confirm('是否确认要删除？')) return ajaxAction(this.href);"));

	$event_name = '回复消息';     
	if(in_array($item['WxMenu']['type'],array('view','view_limited'))) {
		$event_name = '打开网址';  
	}       

            $row_item = array(
                $item['WxMenu']['name'],
				$event_name,
				($item['WxMenu']['type'] == 'view' ? ($item['WxMenu']['link']?'<a target="_blank" href="'.$item['WxMenu']['link'].'">查看网址</a>':'<small>有二级时无需设置</small>' ): $item['WxMenu']['slug']),
                $actions,
            );

			if( strlen($item['WxMenu']['name']) > 16 ) { $row_item[2] .= '<br>子菜单标题超过了16个字节';}
			elseif( strlen($item['WxMenu']['link']) > 256 && $item['WxMenu']['type'] == 'view' ) { $row_item[2] .= '<br>链接超过了256字节';}
			elseif( strlen($item['WxMenu']['slug']) > 128 && $item['WxMenu']['type'] == 'click' ) { $row_item[2] .= '<br>消息接口推送Key值超过了128字节';}


			if($item['WxMenu']['type'] == 'view_limited' || $item['WxMenu']['type'] == 'media_id' ) {
					$row_item[2] = $item['WxMenu']['media_id'] ? $item['WxMenu']['media_id'] : '<small class="text-danger" >需要选择素材</small>';
			}
			$rows[] = $row_item;

			foreach($item['children'] as $child)
			{
				$sub_actions = $this->Html->link('修改', array('controller'=>'wx_menus','action' => 'edit', $child['WxMenu']['id']));
                $sub_actions .= ' &nbsp; ' . $this->Html->link('排序前移', array('controller'=>'wx_menus','action' => 'moveUp', $child['WxMenu']['id']));
				$sub_actions .= ' &nbsp; ' . $this->Html->link('删除', array('controller'=>'wx_menus','action' => 'delete', $child['WxMenu']['id']),array('onclick'=>"if(confirm('是否确认要删除？')) return ajaxAction(this.href);"));
				$event_name = '回复消息';     
				if(in_array($child['WxMenu']['type'],array('view','view_limited'))) {
					$event_name = '打开网址';  
				}  
            	$row_item = array(
                	'<span style="color:#ddd;">| - - - - &nbsp;</span>'.$child['WxMenu']['name'],
					$event_name,
					($child['WxMenu']['type'] == 'view' ? ($child['WxMenu']['link']?'<a target="_blank" href="'.$child['WxMenu']['link'].'">查看网址</a>':'<small class="text-danger" >需要设置网址</small>') : ($child['WxMenu']['slug']?$child['WxMenu']['slug']:'<small class="text-danger" >需要设置事件</small>')),
               		$sub_actions,
            	);

				if( strlen($child['WxMenu']['name']) > 40 ) { $row_item[2] .= '<br>子菜单标题超过了40个字节';}
				elseif( strlen($child['WxMenu']['link']) > 256  && $child['WxMenu']['type'] == 'view' ) { $row_item[2] .= '<br>链接超过了256字节';}
				elseif( strlen($child['WxMenu']['slug']) > 128  && $child['WxMenu']['type'] == 'click' ) { $row_item[2] .= '<br>消息接口推送Key值超过了128字节';}

				if($child['WxMenu']['type'] == 'view_limited' || $child['WxMenu']['type'] == 'media_id' ) {
					$row_item[2] = $child['WxMenu']['media_id'] ? $child['WxMenu']['media_id'] : '<small class="text-danger" >需要选择素材</small>';
				}
				$rows[] = $row_item;
			}
        }
        echo $this->Html->tableCells($rows);
    ?>
    </table>
    
    
       <div class="ui-portlet-header" style="margin-top:80px;">
       	预览效果
       </div>

       <nav class="navbar-collapse bs-navbar-preview  navbar-fixed-bottom" style="position: relative;background:#eee;width:400px;margin:50px auto;padding:0 0;" role="navigation">
	<?php 
		if(empty($top_category_id)) $top_category_id=0;
	echo $this->Section->getNavMenu('WxMenu',
		array(
'conditions' => array(
	'wx_id' => $wx_id,
	'group' => $group,
),
			'ulAttributes'=>array('class'=>'nav navbar-nav'),
                        'defaultClass'=>'ui-state-default',
			'preli'=>'',
			'url'=>'javascript:void(0)',
			'sufli'=>'',
			'separator' => '',
			'fullwidth' => true,
			'inner_separator' => '',
			'maxdepth' => 2,
		));
	?>
	
    </nav>
       
       <div class="alert alert-info">
       <strong>提示：</strong>
       <ul>
       		<li> 微信菜单，一级菜单不超过3个，每个二级菜单数目不超过5个。</li>
       		 <li>
		            一级菜单标题不超过16个字节，子菜单不超过40个字节.
		        </li>
		        <li>
		           发送消息回复规则长度不超过128字节
		        </li>
		        <li>
		           打开链接长度不超过256字节
		        </li>
		        <li>1个字母与数字为1字节，1个汉字为3字节</li>
      		<li> 菜单设置成功后，手机端可能有缓存，取消重新关注公众号可马上看到最新的自定义菜单效果。</li>
      		
      	</ul>
       </div>